package com.google.code.swingonfire.component.page.old;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import com.google.code.swingonfire.component.page.JPagedPaneModel;

public class DefaultJPagedPaneModel implements JPagedPaneModel
{

    private final List<Component> components = new ArrayList<Component>();

    public DefaultJPagedPaneModel()
    {
        super();
    }

    public int addComponent(Component component)
    {
        int result = components.size();

        components.add(component);

        return result;
    }

    public int addComponent(int index, Component component)
    {
        components.add(index, component);

        return index;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Component getComponent(int index)
    {
        return components.get(index);
    }

    public int getIndexOfComponent(String name)
    {
        for (int i = 0; i < components.size(); i++)
        {
            Component component = components.get(i);

            if (name.equals(component.getName()))
            {
                return i;
            }
        }

        return -1;
    }

    public int setComponent(int index, Component component)
    {
        components.set(index, component);

        return index;
    }

    public Component removeComponent(int index)
    {
        return components.remove(index);
    }

    public int getNumberOfComponents()
    {
        return components.size();
    }

    @Override
    public void invalidateComponent(int index, Component component)
    {
        // intentionally left blank
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMinimumComponentIndex()
    {
        return 0;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaximumComponentIndex()
    {
        return getNumberOfComponents() - 1;
    }

}
